<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "user_recipe".
 *
 * @property int $id
 * @property int $user_id 用户id
 * @property int $user_patient_symptom_id 用户患者症状id
 * @property string $price 价格(处方总价)
 * @property string $create_time 操作日期
 * @property int $status 状态
 *
 * @property UserPatientSymptom $userPatientSymptom
 * @property UserRecipeRecord[] $userRecipeRecords
 */
class UserRecipe extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_recipe';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'user_patient_symptom_id'], 'required'],
            [['user_id', 'user_patient_symptom_id', 'status'], 'integer'],
            [['create_time'], 'safe'],
//            [['price'], 'string', 'max' => 10],
            [['user_patient_symptom_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserPatientSymptom::className(), 'targetAttribute' => ['user_patient_symptom_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户id',
            'user_patient_symptom_id' => '用户患者症状id',
            'price' => '价格(处方总价)',
            'create_time' => '操作日期',
            'status' => '状态',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserPatientSymptom()
    {
        return $this->hasOne(UserPatientSymptom::className(), ['id' => 'user_patient_symptom_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserRecipeRecords()
    {
        return $this->hasMany(UserRecipeRecord::className(), ['user_recipe_id' => 'id']);
    }
}
